package com.platform.uaa.advice;

import com.platform.comm.web.results.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局处理Oauth2抛出的异常
 *
 * @author zyk
 */
@Slf4j
@RestControllerAdvice
public class UaaRestControllerAdvice {

  @ResponseBody
  @ExceptionHandler(value = OAuth2Exception.class)
  public JsonResult handleOauth2(OAuth2Exception e) {
    JsonResult result = JsonResult.of();
    return result.fail(e.getMessage());
  }
}
